package com.simple.editor.callback;

/**
 * {@link DefaultUICallbackImpl} provides default implementation of a {@link Callback}.
 * <p/>
 * <p/>
 * User: vsoroka
 * Date: 01.07.13
 * Time: 12:03
 * To change this template use File | Settings | File Templates.
 */
public class DefaultUICallbackImpl implements Callback {

    private final CallbackListener listener;
    private final String operation;

    public DefaultUICallbackImpl() {
        this(null, null);
    }

    public DefaultUICallbackImpl(final String operation, final CallbackListener listener) {
        this.operation = operation;
        this.listener = listener;
    }

    @Override
    public void onComplete() {
        if (listener != null) {
            listener.addInfo(String.format("%s successfully completed", operation));
        }
    }

    @Override
    public void onFailure(Exception ex) {
        if (listener != null) {
            listener.addError(String.format("%s failed! %s", operation, ex.getMessage()));
        }
    }

    @Override
    public void onStart() {
        if (listener != null) {
            listener.addInfo(String.format("%s started...", operation));
        }
    }
}
